{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71000c2a-b2f5-4bb0-aa68-9dbbcbd7a1ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "from matplotlib import MatplotlibDeprecationWarning\n",
    "warnings.filterwarnings('ignore', category=MatplotlibDeprecationWarning)\n",
    "from sympy import *\n",
    "from einsteinpy.symbolic import MetricTensor, ChristoffelSymbols\n",
    "init_printing()\n",
    "\n",
    "lon, lat, a, b, eta, x, y, s, R, Ra, Rb, Rr = symbols('lambda theta alpha beta eta x y sigma R R_alpha R_beta R_\\eta')\n",
    "# p1~4\n",
    "lon = a\n",
    "lat = atan(cos(a)*tan(b))\n",
    "# p5\n",
    "\n",
    "# p6\n",
    "\n",
    "R = Ra*a + Rb*b + Rr*eta\n",
    "\n",
    "dlonda = diff(lon,a)\n",
    "dlatda = diff(lat,a)\n",
    "dlondb = diff(lon,b)\n",
    "dlatdb = diff(lat,b)\n",
    "dRda   = diff(R,a)\n",
    "dRdb   = diff(R,b)\n",
    "\n",
    "A = simplify(Matrix([[R*cos(lat)*dlonda,R*cos(lat)*dlondb,0 ],\n",
    "                     [R*dlatda         ,R*dlatdb         ,0 ],\n",
    "                     [Ra               ,Rb               ,Rr]])\n",
    "            )\n",
    "A = simplify(A.subs(a,atan(x)).subs(b,atan(y)))\n",
    "A = simplify(A.subs(1+x**2+y**2, s**2))\n",
    "\n",
    "iA = simplify(A**-1)\n",
    "\n",
    "G = simplify(transpose(A)*A)\n",
    "\n",
    "iG = simplify(G**-1)\n",
    "#iG=[[(1 + cos(a)**2*tan(b)**2)**2/((Ra*a + Rb*b + Rr*eta)**2*(sec(b)**2 - sin(a)**2*tan(b)**2)), \n",
    "#    ((cos(a)**2 + cot(b)**2)**2*sin(b)**2*tan(a)*tan(b))/((Ra*a + Rb*b + Rr*eta)**2*(csc(b)**2 - sin(a)**2)), \n",
    "#    -(((Ra + Rb*cos(b)*sin(b)*tan(a))*(cot(b) + cos(a)**2*tan(b))**2)/(Rr*(Ra*a + Rb*b + Rr*eta)**2*\n",
    "#       (csc(b)**2 - sin(a)**2)))], [((cos(a)**2 + cot(b)**2)**2*sin(b)**2*tan(a)*tan(b))/\n",
    "#     ((Ra*a + Rb*b + Rr*eta)**2*(csc(b)**2 - sin(a)**2)), (cos(b)*cot(b)*sec(a) + cos(a)*sin(b))**2/\n",
    "#     ((Ra*a + Rb*b + Rr*eta)**2*(csc(b)**2 - sin(a)**2)), \n",
    "#    ((Rb*cot(b) + Ra*cos(a)*sin(a))*(cos(b)*cot(b)*sec(a) + cos(a)*sin(b))**2*tan(b))/\n",
    "#     (Rr*(Ra*a + Rb*b + Rr*eta)**2*(-csc(b)**2 + sin(a)**2))], \n",
    "#   [-(((Ra + Rb*cos(b)*sin(b)*tan(a))*(cot(b) + cos(a)**2*tan(b))**2)/(Rr*(Ra*a + Rb*b + Rr*eta)**2*\n",
    "#       (csc(b)**2 - sin(a)**2))), ((Rb*cot(b) + Ra*cos(a)*sin(a))*(cos(b)*cot(b)*sec(a) + cos(a)*sin(b))**2*\n",
    "#      tan(b))/(Rr*(Ra*a + Rb*b + Rr*eta)**2*(-csc(b)**2 + sin(a)**2)), \n",
    "#    (2*Rb**2*cos(b)**2 + cot(b)**2*(Ra**2 + Rb**2*cos(b)**2*sec(a)**2) + (Ra*a + Rb*b + Rr*eta)**2*\n",
    "#       (csc(b)**2 - sin(a)**2) + cos(a)**2*(2*Ra**2 + Rb**2*sin(b)**2) + Ra*Rb*sin(2*a)*sin(2*b) + \n",
    "#      2*Ra*Rb*cos(b)**2*cot(b)*tan(a) + 2*Ra*Rb*cos(a)**3*sin(a)*sin(b)**2*tan(b) + Ra**2*cos(a)**4*tan(b)**2)/\n",
    "#     (Rr**2*(Ra*a + Rb*b + Rr*eta)**2*(csc(b)**2 - sin(a)**2))]]\n",
    "\n",
    "#gamma = simplify(ChristoffelSymbols.from_metric(MetricTensor(G, (a, b, eta))).tensor())\n",
    "\n",
    "iG"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d741d2b-3a9d-48cc-81de-1eb62c7b0256",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc-autonumbering": true,
  "toc-showcode": true,
  "toc-showmarkdowntxt": true
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
